package com.yiip.mr.etl.gulivideo;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class GuliVideoDriver implements Tool {

    private Configuration configuration;

    @Override
    public int run(String[] args) throws Exception {
        //1、设置configurion
        //2、设置jar路径
        //3、设置map的输入输出类型
        //4、设置最终输出类型
        //5、设置路径
        //6、提交job

        Job job = Job.getInstance(configuration);

        job.setJarByClass(GuliVideoDriver.class);

        job.setMapperClass(GuliVideoMapper.class);

        job.setMapOutputKeyClass(NullWritable.class);
        job.setMapOutputValueClass(Text.class);

        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(Text.class);

        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        boolean result = job.waitForCompletion(true);
        return result ? 1 : 0;
    }

    @Override
    public void setConf(Configuration conf) {
        configuration = conf;
    }

    @Override
    public Configuration getConf() {
        return configuration;
    }

    public static void main(String[] args) {

        args = new String[2];
        args[0] = "E:/bigDataDemo/etl/gulivideo/input/0.txt";
        args[1] = "E:/bigDataDemo/etl/gulivideo/output";
        Configuration configuration = new Configuration();
        try {
            ToolRunner.run(configuration,new GuliVideoDriver(),args);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
